﻿using Dapper;
using SXFramWork.Core;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Threading.Tasks;

namespace SXFramWork.Core
{
    public interface ISql<TEntity>:ISql  where TEntity : class, new()
    {
        /// <summary>
        /// 查询一个对象【dapper】
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="param">参数</param>
        /// <param name="unitOfWork">工作单元</param>
        /// <returns></returns>
        Task<TEntity> GetDataAsync(string sql, object param = null, IUnitOfWork unitOfWork=null);
        /// <summary>
        /// 查询集合【dapper】
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="param">参数</param>
        /// <param name="unitOfWork">工作单元</param>
        /// <returns></returns>
        Task<List<TEntity>> GetDataListAsync(string sql, object param = null, IUnitOfWork unitOfWork = null);
        /// <summary>
        /// 查询集合并指定返回类型【dapper】
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="param">参数</param>
        /// <param name="unitOfWork">工作单元</param>
        /// <returns></returns>
        Task<List<TResult>> GetDataListAsync<TResult>(string sql, object param = null, IUnitOfWork unitOfWork = null);
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="model">查询模型</param>
        /// <param name="check">模糊查询条件</param>
        /// <param name="where">附加条件</param>
        /// <param name="param">参数</param>
        /// <param name="orderBy">排序</param>
        /// <param name="unitOfWork">工作单元</param>
        /// <returns></returns>
        Task<List<TEntity>> GetPageListAsync(string sql, QueryModel model, Dictionary<string, object> check = null, string where = "", object param = null,string orderBy="", IUnitOfWork unitOfWork = null);
        /// <summary>
        /// 批量插入【高效率】
        /// </summary>
        /// <param name="entityList">实体集合</param>
        /// <param name="tablename">表名</param>
        /// <param name="unitOfWork">工作单元</param>
        /// <returns></returns>
        Task AddDataListAsync(List<TEntity> entityList, string tablename = "", IUnitOfWork unitOfWork = null);
    }
}
